//
//  NYWrongAnswerTipCell.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/5.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYWrongAnswerTipCell.h"
@interface NYWrongAnswerTipCell ()
@property(nonatomic, strong) TTTAttributedLabel *titleLabel;
@end
@implementation NYWrongAnswerTipCell
- (BOOL)shouldUpdateCellWithObject:(NICellObject *)object atIndexPath:(NSIndexPath *)indexPath
{
        self.indexPath = indexPath;
        self.subjectModel = (NYSubjectModel *)object.userInfo;
        return YES;
}

- (void)setSubjectModel:(NYSubjectModel *)subjectModel
{
        _subjectModel = subjectModel;
        [self updateContent];
}
- (void)updateContent
{
        // 填空
        if (self.subjectModel.question_type == NYQuestionTypeFillBlanks) {
                
                self.titleLabel.text = [NSString stringWithFormat:@"错误答案：%@",NOT_NULL_STRING_DEFAULT_EMPTY(self.subjectModel.wrong_answer_arr.firstObject)];
        } else {
                NSMutableArray <NSString *>*array = [NSMutableArray arrayWithCapacity:self.subjectModel.wrong_answer_arr.count];
                [self.subjectModel.wrong_answer_arr enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                        [array addObject:[CoBaseUtils getLetterFromIndex:obj]];
                }];
                
                [array sortUsingSelector:@selector(compare:)];
                
                self.titleLabel.text = [NSString stringWithFormat:@"错误答案：%@",[array componentsJoinedByString:@" "]];
        }
}
- (void)setupView
{
        [super setupView];
        UIView *contentView = [[UIView alloc] init];
        [self.contentView addSubview:contentView];
        [contentView addSubview:self.titleLabel];
        
        [contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.contentView).mas_offset(__WGHeight(15));
                make.left.equalTo(self.contentView).mas_offset(__WGHeight(16));
                make.bottom.equalTo(self.contentView).mas_offset(-__WGHeight(16)).priorityLow();
                make.right.equalTo(self.contentView).mas_offset(-__WGHeight(16));
        }];
        
        [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.left.right.bottom.equalTo(contentView);
        }];
}

- (TTTAttributedLabel *)titleLabel
{
        if (_titleLabel == nil) {
                _titleLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
                _titleLabel.font = WGSystem14Font;
                _titleLabel.textColor = UIColorHex(0xFA8D00);
        }
        return _titleLabel;
}
@end
